package com.wnxy.sddfp.access.service.impl;
import java.time.LocalDateTime;

import com.wnxy.sddfp.access.controller.TradeLogController;
import com.wnxy.sddfp.access.entity.TradeLog;
import com.wnxy.sddfp.access.mapper.TradeLogMapper;
import com.wnxy.sddfp.access.service.ITradeLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wnxy.sddfp.common.model.dto.bank.BankCardAddDTO;
import com.wnxy.sddfp.common.model.dto.bank.SignatureDto;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 托管系统交易记录表 服务实现类
 * </p>
 *
 * @author shuaige
 * @since 2025-03-20
 */
@Service
public class TradeLogServiceImpl extends ServiceImpl<TradeLogMapper, TradeLog> implements ITradeLogService {

    /**
     * @SneakyThrows 是 Lombok 提供的注解。它的作用是：
     * 自动抛出受检异常（Checked Exception） 而不需要显式地在方法声明中写 throws Exception。
     * 在编译期间，Lombok 会自动修改字节码，将异常抛出。
     *
     * @param bankCardAddDTO
     * @return
     */
    @SneakyThrows
    @Override
    public SignatureDto proxyBindCardLog(BankCardAddDTO bankCardAddDTO) {

        //1.创建日志
        TradeLog tradeLog = new TradeLog();
        tradeLog.setReqCode(bankCardAddDTO.getReqCode());
        //指定绑卡字符
        tradeLog.setReqType("USER_BIND_CARD");
        //userId
        tradeLog.setObjectId(bankCardAddDTO.getUserId());
        //日志时间
        tradeLog.setCreateDate(LocalDateTime.now());
        //银行返回数据时对下面数据进行更新
        tradeLog.setSynchronizeStatus(0);
        tradeLog.setConfirmDate(LocalDateTime.now());
        tradeLog.setResponseData("");

        save(tradeLog);

        //默认访问银行系统
        SignatureDto signatureDto = new SignatureDto();
        signatureDto.setBankUrl("http://localhost:5600");
        signatureDto.setPlatformNo("ICBC");
        signatureDto.setReqData("{\"success\":\"绑卡成功\"}");
        signatureDto.setReqCode(bankCardAddDTO.getReqCode());

        return signatureDto;
    }
}
